﻿using Koala.Pro.CodeGenerator.UI.Common;

namespace Koala.Pro.CodeGenerator.UI.DatabaseModel.Schema
{
    public class ColumnInfo
    {
        private int _ordinal;

        private NameElement _name;

        private string _dataType;

        private int _typeId;

        private NameElement _netType;

        private NameElement _javaType;

        private int _maxLength;

        private int _fieldPrecise;

        private string _description = string.Empty;

        private bool _allowDBNull;

        private bool _isPrimaryKey;

        private bool _isForeignKey;

        private KeyInfo _fKReference;

        private IList<KeyInfo> _pKBeReferences = new List<KeyInfo>();

        private bool _isReadOnly;

        private bool _autoIncrement;

        private bool _unique;

        private string _defaultValue = string.Empty;

        private TableInfo _parentTable;

        private string _uiControlType;

        public int Ordinal
        {
            get
            {
                return _ordinal;
            }
            set
            {
                _ordinal = value;
            }
        }

        public NameElement Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }

        public string DataType
        {
            get
            {
                return _dataType;
            }
            set
            {
                _dataType = value;
            }
        }

        public int DataTypeId
        {
            get
            {
                return _typeId;
            }
            set
            {
                _typeId = value;
            }
        }

        public NameElement NetType
        {
            get
            {
                return _netType;
            }
            set
            {
                _netType = value;
            }
        }

        public NameElement JavaType
        {
            get
            {
                return _javaType;
            }
            set
            {
                _javaType = value;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return _isReadOnly;
            }
            set
            {
                _isReadOnly = value;
            }
        }

        public int MaxLength
        {
            get
            {
                return _maxLength;
            }
            set
            {
                _maxLength = value;
            }
        }

        public int FieldPrecise
        {
            get
            {
                return _fieldPrecise;
            }
            set
            {
                _fieldPrecise = value;
            }
        }

        public string DefaultValue
        {
            get
            {
                return _defaultValue;
            }
            set
            {
                _defaultValue = value;
            }
        }

        public bool AllowDBNull
        {
            get
            {
                return _allowDBNull;
            }
            set
            {
                _allowDBNull = value;
            }
        }

        public bool AutoIncrement
        {
            get
            {
                return _autoIncrement;
            }
            set
            {
                _autoIncrement = value;
            }
        }

        public bool Unique
        {
            get
            {
                return _unique;
            }
            set
            {
                _unique = value;
            }
        }

        public bool IsPrimaryKey
        {
            get
            {
                return _isPrimaryKey;
            }
            set
            {
                _isPrimaryKey = value;
            }
        }

        public IList<KeyInfo> PKBeReferences
        {
            get
            {
                return _pKBeReferences;
            }
            set
            {
                _pKBeReferences = value;
            }
        }

        public bool IsForeignKey
        {
            get
            {
                return _isForeignKey;
            }
            set
            {
                _isForeignKey = value;
            }
        }

        public KeyInfo FKReference
        {
            get
            {
                return _fKReference;
            }
            set
            {
                _fKReference = value;
            }
        }

        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                _description = value;
            }
        }

        public bool IsKey
        {
            get
            {
                if (IsPrimaryKey || IsForeignKey)
                {
                    return true;
                }
                return false;
            }
        }

        public TableInfo ParentTable
        {
            get
            {
                return _parentTable;
            }
            set
            {
                _parentTable = value;
            }
        }

        public string UIControlType
        {
            get
            {
                return _uiControlType;
            }
            set
            {
                _uiControlType = value;
            }
        }

        public bool IsSystemColumn { get; set; }

        public bool IsDateTime { get; set; }

        public bool IsNumeric { get; set; }

        public override string ToString()
        {
            return StringUtil.ToString(this);
        }
    }

}
